package com.atguigu.boot.activemq.produce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import java.util.UUID;

/**
 * @Auther 赵乾坤
 * @Date 2021-04-17 10:08
 */
@Component
public class Queue_Produce {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;


    public void produceMsg() {
        jmsMessagingTemplate.convertAndSend(queue, "**********" + UUID.randomUUID().toString().substring(0, 6));//左闭右开
    }

    //间隔三秒定投
    @Scheduled(fixedDelay = 3000)//过来多少秒
    public void produceMsgScheduled() {
        jmsMessagingTemplate.convertAndSend(queue, "**********Scheduled" + UUID.randomUUID().toString().substring(0, 6));//左闭右开
        System.out.println("*******produceMsgScheduled send ok");
    }
}
